package Server.Poker.PDK;

import java.math.BigDecimal;
import java.util.Stack;
import org.json.JSONObject;

import java.util.Vector;

public class Message {

}

class MSG_PACKET {

	int m_wMsgType;
	int m_wMsgLen;
	int m_wSubMsgType;

	public String getJsonData() {
		String sTmp = String.format(",\"m_wMsgType\":%d,\"m_wSubMsgType\":%d", m_wMsgType, m_wSubMsgType);
		return sTmp;
	}

	public void SetMsgType(int wMsgType) {
		m_wMsgType = wMsgType;
	}

}

class MSG_FOR_USER extends MSG_PACKET {
	int GetUserKey() {
		return m_dwUserKey;
	}

	void SetUserKey(int dwKey) {
		m_dwUserKey = dwKey;
	}

	MSG_FOR_USER() {
		m_dwUserKey = 0;
	}

	int m_dwUserKey;

	public String getJsonData() {
		String sTmp = String.format(",\"m_dwUserKey\":%d", m_dwUserKey);
		return super.getJsonData() + sTmp;
	}
};

class MSG_FOR_TABLE extends MSG_PACKET {
	int wSubCmd;
	int wChairID;

	Object byData;
	String strData;

	public String getJsonData() {
		String strHeader = super.getJsonData();
		String sTmp = String.format("%s,\"wSubCmd\":%d,\"wChairID\":%d,\"dataStr\":{%s}", strHeader, wSubCmd, wChairID,
				strData);
		return sTmp;
	}

};

class tagUserData {
	// 用户属性
	int dwFaceID; // 头像索引
	int dwUserID; // 用户 I D
	int dwGroupID; // 社团索引
	int dwGameID; // 用户 I D
	int dwUserRight; // 用户等级
	int dwMasterRight; // 管理权限
	String szName; // 用户名字
	String szGroupName; // 社团名字
	String szUnderWrite; // 个性签名

	// 用户属性
	int cbGender; // 用户性别
	int cbMemberOrder; // 会员等级
	int cbMasterOrder; // 管理等级
	int cbUserStatus; // 用户状态

	// 用户状态
	int wTableID; // 桌子号码
	int wChairID; // 椅子位置

	// 用户积分
	int lScore; // 用户分数
	int lGameGold; // 游戏金币（话费豆）
	int lStorageGold; // 存储金币（话费豆）
	int lWinCount; // 胜利盘数
	int lLostCount; // 失败盘数
	int lDrawCount; // 和局盘数
	int lFleeCount; // 断线数目
	int lExperience; // 用户经验
	int lStorageScore; // 存储积分

	tagUserData() {

	}

	String getJsonData() {
		String buffer = String.format("{ \"dwUserID\":%d, \"szName\":\"%s\" , \"wChairID\":%d ,\"cbGender\":%d }",
				dwUserID, szName, wChairID, cbGender);
		return buffer;
	}
};

// 用户信息结构
class tagUserProfile {
	String szUserName; // 用户账户
	String szUserPass; // 用户密码
	String szUserRealName; // 用户真实姓名
	String szUserRealIDCard; // 用户身份证号
	String szUserRealPhone; // 用户手机

	tagUserProfile() {
	}

	String getJsonData() {
		String buffer = String.format("{\"szUserName\":\"%s\"}", "");
		return buffer;
	}
};

class tagUserEducateData {
	int lEducateScore; // 教育分数
	int lEducateGiftTime; // 教育送分时间

	tagUserEducateData() {
	}

	String getJsonData() {
		String buffer = String.format("{\"lEducateScore\":%d}", lEducateScore);
		return buffer;
	}
};

class Packet_LoginResult extends MSG_FOR_USER {
	enum enumLoginErrorCode {
		enumSuccess, ELoginErrorCode_Wrong_Auth, ELoginErrorCode_Wrong_AlreadyLogin, ELoginErrorCode_ServeUnavailble, ELoginErrorCode_VersionTooLow, ELoginErrorCode_Unknown,
	};

	public Packet_LoginResult() {
		byResult = 0;
		// Constants.memset(UserData,0);
	}

	int byResult;
	tagUserData UserData = new tagUserData();
	tagUserProfile UserProfile = new tagUserProfile();
	tagUserEducateData UserEducateData = new tagUserEducateData();

	public String getJsonData() {
		String sTmp = String.format(",\"byResult\":%d,\"UserData\":%s,\"UserProfile\":%s,\"UserEducateData\":%s",
				byResult, UserData.getJsonData(), UserProfile.getJsonData(), UserEducateData.getJsonData());
		return super.getJsonData() + sTmp;
	}
};

class Packet_UserEnterRoomResult extends MSG_FOR_USER {

	static int enumSuccess = 0;
	static int enumScoreNotEnough = 1;
	static int enumTableIsFull = 2;

	int byResult;
	int dwUserID;
	int lGameGenre;
	String szRoomName;

	public String getJsonData() {
		String sTmp = String.format(",\"byResult\":%d,\"dwUserID\":\"%d\"", byResult, dwUserID);
		return super.getJsonData() + sTmp;
	}
};

// 用户加入桌子
class Packet_UserSit extends MSG_FOR_USER {

	static int enumSuccess = 0;
	static int enumScoreNotEnough = 1;
	static int enumTableIsFull = 2;

	int byResult;
	int dwUserID;// 新加进的用户ID
	int wCharID;// 桌子索引号
	int wServerType;

	public String getJsonData() {
		String sTmp = String.format(",\"byResult\":%d,\"dwUserID\":%d,\"wCharID\":%d,\"wServerType\":%d", byResult,
				dwUserID, wCharID, wServerType);
		return super.getJsonData() + sTmp;
	}
};

// 分数类型
enum enScoreKind {
	enScoreKind_Win, // 胜
	enScoreKind_Lost, // 输
	enScoreKind_Draw, // 和
	enScoreKind_Flee, // 逃
	enScoreKind_Service, // 服务
	enScoreKind_Present, // 赠送
};

// 积分信息
class tagScoreInfo {
	int lScore; // 游戏积分
	int lGameGold; // 游戏金币
	int lRevenue; // 游戏积分
	enScoreKind ScoreKind; // 分数类型
};

// 桌子状态信息
class CMD_GR_TableStatus {
	int wTableID; // 桌子号码
	int bPlayStatus; // 游戏状态

	String getJsonData() {
		String sTmp = String.format("  \"wTableID\":%d  ,\"bPlayStatus\":%d ", wTableID, bPlayStatus);
		return sTmp;
	}
};

// 桌子信息
class CMD_GR_TableInfo {
	// 用户积分信息
	int wTableID;
	int bStatus;// 桌子的状态WK_FREE什么的
	int bReserved;
	tagUserData UserData[] = new tagUserData[3];

	String getJsonData() {

		String sTmp = String.format("\"wTableID\":%d ,\"bStatus\":%d,\"bReserved\":%d  ,\"UserData\":[%s,%s,%s]",
				wTableID, bStatus, bReserved, UserData[0].getJsonData(), UserData[1].getJsonData(),
				UserData[2].getJsonData());
		return sTmp;
	}
};

// 用户叫分
class CMD_C_LandScore {
	int bLandScore; // 地主分数

	String getJsonData() {

		String sTmp = String.format("  \"bLandScore\":%d ", bLandScore);
		return sTmp;
	}
};

// 游戏状态
class CMD_S_StatusFree {
	int lBaseScore; // 基础积分
	int tableStart = 0;
	String getJsonData() {
		String sTmp = String.format("\"lBaseScore\":%d", lBaseScore);
		return sTmp;
	}
};

// 游戏状态
class CMD_S_StatusScore {
	int bLandScore; // 地主分数
	int lBaseScore; // 基础积分
	int wFirstUser; // 首叫玩家
	int wBankerUser; // 庄家用户
	int wCurrentUser; // 当前玩家
	int bScoreInfo[] = new int[3]; // 叫分信息
	int bCardData[][] = new int[3][20]; // 手上扑克
	int bBackCard[] = new int[3]; // 底牌扑克
	boolean bUserTrustee[] = new boolean[Constants.DDZ_PLAYER]; // 玩家托管

	String getJsonData() {

		String sTmp = String.format(
				"\"bLandScore\":%d  ,\"lBaseScore\":%d,\"wFirstUser\":%d,\"wBankerUser\":%d,\"wCurrentUser\":%d ,\"bScoreInfo\":%s,\"bCardData\": [%s,%s,%s]   ,\"bBackCard\":%s,\"bUserTrustee\":%s ",
				bLandScore, lBaseScore, wFirstUser, wBankerUser, wCurrentUser, Constants.sprintf_Array(bScoreInfo, 3),
				Constants.sprintf_Array(bCardData[0], 20), Constants.sprintf_Array(bCardData[1], 20),
				Constants.sprintf_Array(bCardData[2], 20), Constants.sprintf_Array(bBackCard, 3),
				Constants.sprintf_Array(bUserTrustee, Constants.DDZ_PLAYER));
		return sTmp;
	}

};

// 游戏状态
class CMD_S_StatusPlay {
	int wLandUser; // 坑主玩家
	int wBombTime; // 炸弹倍数
	int lBaseScore; // 基础积分
	int bLandScore; // 地主分数
	int wFirstUser; // 首叫玩家
	int wLastOutUser; // 出牌的人
	int wCurrentUser; // 当前玩家

	int wOutBombCount; // 炸弹数目

	int bBackCard[] = new int[3]; // 底牌扑克
	int bCardData[][] = new int[3][20]; // 手上扑克
	int bCardCount[] = new int[3]; // 扑克数目
	int bTurnCardCount; // 基础出牌
	int bTurnCardData[] = new int[20]; // 出牌列表
	int bScoreTimes[] = new int[3]; // 分数倍数
	boolean bUserTrustee[] = new boolean[Constants.DDZ_PLAYER]; // 玩家托管

	String getJsonData() {

		String sTmp = String.format(
				"\"wLandUser\":%d  ,\"wBombTime\":%d,\"lBaseScore\":%d,\"bLandScore\":%d,\"wFirstUser\":%d  ,\"wLastOutUser\":%d ,\"wCurrentUser\":%d    ,\"wOutBombCount\":%d,\"bBackCard\":%s,\"bCardData\": [%s,%s,%s]   ,\"bCardCount\":%s,\"bTurnCardCount\":%d    ,\"bTurnCardData\":%s ,\"bScoreTimes\":%s ,\"bUserTrustee\":%s ",
				wLandUser, wBombTime, lBaseScore, bLandScore, wFirstUser, wLastOutUser, wCurrentUser, wOutBombCount,
				Constants.sprintf_Array(bBackCard, 3), Constants.sprintf_Array(bCardData[0], 20),
				Constants.sprintf_Array(bCardData[1], 20), Constants.sprintf_Array(bCardData[2], 20),
				Constants.sprintf_Array(bCardCount, 3), bTurnCardCount, Constants.sprintf_Array(bTurnCardData, 20),
				Constants.sprintf_Array(bScoreTimes, 3), Constants.sprintf_Array(bUserTrustee, Constants.DDZ_PLAYER));
		return sTmp;
	}
};

// 用户离开桌子
class CMD_S_UserLeaveTable {
	int dwUserID;// 新加进的用户ID
	int wCharID;// 桌子索引号

	String getJsonData() {

		String sTmp = String.format("\"dwUserID\":%d ,\"wCharID\":%d ", dwUserID, wCharID);
		return sTmp;
	}
};

// 用户状态
class CMD_GR_UserStatus {
	int dwUserID; // 数据库 ID
	int wTableID; // 桌子位置
	int wChairID; // 椅子位置
	int cbUserStatus; // 用户状态

	String getJsonData() {
		String sTmp = String.format("  \"dwUserID\":%d    ,\"wTableID\":%d   ,\"wChairID\":%d,\"cbUserStatus\":%d ",
				dwUserID, wTableID, wChairID, cbUserStatus);
		return sTmp;
	}
};

// 桌子信息
class CMD_GR_UserInfo {
	// 用户积分信息
	tagUserData UserData;

	String getJsonData() {

		String sTmp = String.format("\"UserData\":%s", UserData.getJsonData());
		return sTmp;
	}
};

// 用户分数
class CMD_GR_UserScore {
	int dwUserID; // 用户 I D

	int lScore; // 用户分数
	int lGameGold; // 游戏金币//
	int lStorageGold; // 存储金币
	int lWinCount; // 胜利盘数
	int lLostCount; // 失败盘数
	int lDrawCount; // 和局盘数
	int lFleeCount; // 断线数目
	int lExperience; // 用户经验

	String getJsonData() {

		String sTmp = String.format(
				"  \"dwUserID\":%d    ,\"lScore\":%d   ,\"lGameGold\":%d,\"lStorageGold\":%d ,\"lWinCount\":%d     ,\"lLostCount\":%d   ,\"lDrawCount\":%d  ,\"lFleeCount\":%d ,\"lExperience\":%d       ",
				dwUserID, lScore, lGameGold, lStorageGold, lWinCount, lLostCount, lDrawCount, lFleeCount, lExperience);
		return sTmp;
	}
};

// 放弃出牌
class CMD_S_PassCard {
	int bNewTurn; // 一轮开始
	int wPassUser; // 放弃玩家
	int wCurrentUser; // 当前玩家

	String getJsonData() {

		String sTmp = String.format("  \"bNewTurn\":%d  ,\"wPassUser\":%d , \"wCurrentUser\":%d  ", bNewTurn, wPassUser,
				wCurrentUser);
		return sTmp;
	}
};

// 用户出牌
class CMD_S_OutCard {
	int bCardCount; // 出牌数目
	int wCurrentUser; // 当前玩家
	int wOutCardUser; // 出牌玩家
	int bCardData[] = new int[20]; // 扑克列表

	String getJsonData() {

		String sTmp = String.format(
				"  \"bCardCount\":%d  ,\"wCurrentUser\":%d , \"wOutCardUser\":%d  ,\"bCardData\": [", bCardCount,
				wCurrentUser, wOutCardUser);
		String str = sTmp;
		for (int i = 0; i < 20 && i < bCardCount; i++) {
			sTmp = String.format(i == 0 ? "%d" : ",%d", bCardData[i]);
			str += sTmp;
		}
		str += "]";
		return str;
	}
};

// 出牌数据包
class CMD_C_OutCard {
	int bCardCount; // 出牌数目
	int bCardData[] = new int[20]; // 扑克列表

	String getJsonData() {

		String sTmp = String.format("  \"bCardCount\":%d ,\"bCardData\":%s ", bCardCount,
				Constants.sprintf_Array(bCardData, 20));
		return sTmp;
	}

	void setCardData(String dataStr) {
		String [] vs = dataStr.split(",");
		if (vs.length == bCardCount)
		{
			for (int i = 0; i < vs.length && i < 20; i++)
			{
				bCardData[i] = Constants.atoi(vs[i]);
			}
		}
	}
};

//出牌数据包
class CMD_CURRENT_OutCard {
	int bCardCount; // 出牌数目
	int bCardData[] = new int[20]; // 扑克列表

	void setCardData(int[] cardData,int cardCount) {
		for (int i = 0; i < cardCount && i < 20; i++)
		{
			bCardData[i] = cardData[i];
		}
	}
};

// 游戏结束
class CMD_S_GameEnd {
	int lGameTax; // 游戏税收
	int dwUserID[] = new int[3]; // 玩家ID
	double lGameScore[] = new double[3]; // 游戏积分
	int bCardCount[] = new int[3]; // 扑克数目
	int bCardData[] = new int[54]; // 扑克列表
	int bBackCard[] = new int[3]; // 底牌扑克
	int m_bombCountArray[] = new int[3];//炸弹数量
	int bGuanmen[] = new int[3];
	double allScoreArray[] = new double[3];

	String getJsonData() {
		String sTmp = String.format(
				"  \"lGameTax\":%d ,\"dwUserID\":%s  ,\"lGameScore\":%s ,\"bCardCount\":%s ,\"bCardData\":%s ,\"bBackCard\":%s,\"m_bombCountArray\":%s,\"bGuanmen\":%s ,\"allScoreArray\":%s ",
				lGameTax, Constants.sprintf_Array(dwUserID, 3), Constants.sprintf_Double(lGameScore, 3),
				Constants.sprintf_Array(bCardCount, 3), Constants.sprintf_Array(bCardData, 54),
				Constants.sprintf_Array(bBackCard, 3),Constants.sprintf_Array(m_bombCountArray, 3)
				,Constants.sprintf_Array(bGuanmen, 3),Constants.sprintf_Double(allScoreArray, 3));
		return sTmp;
	}

};

//class tagUserReport {
//	int lUid;
//	int zhaDan;
//	String zhanji;
//	int cntDianPao;
//	int cntGang;	
//	int lWinScore;
//	int lLoseScore;
//	int lResultScore;
//
//	public String toString() {
//		String data = String.format("%d#%d#%d#%d#%d#%d#%d#%d", lUid, cntZiMo, cntHu, cntDianPao,cntGang, lWinScore, lLoseScore,
//				lResultScore);
//
//		return data;
//	}
//};

// 发送扑克
class CMD_S_SendAllCard {
	int wCurrentUser; // 当前玩家
	int bCardData[][] = new int[Constants.DDZ_PLAYER][20]; // 扑克列表
	int bBackCardData[] = new int[3]; // 底牌扑克
	int bExtCard;

	String getJsonData() {
		String strbCardData = Constants.sprintf_Array(bCardData[0], 20);
		String strbCardData1 = Constants.sprintf_Array(bCardData[1], 20);
		String strbCardData2 = Constants.sprintf_Array(bCardData[2], 20);
		String strbackCardData = Constants.sprintf_Array(bBackCardData, 3);

		String sTmp = String.format(
				"  \"wCurrentUser\":%d  ,\"bExtCard\":%d ,\"bCardData\":[%s,%s,%s] ,\"bBackCardData\":%s", wCurrentUser,
				bExtCard, strbCardData, strbCardData1, strbCardData2, strbackCardData);

		return sTmp;
	}
};

// 托管结构
class CMD_C_UserTrustee {
	int wUserChairID; // 玩家椅子
	boolean bTrustee; // 托管标识

	String getJsonData() {
		String sTmp = String.format("  \"wUserChairID\":%d  ,\"bTrustee\":%d  ", wUserChairID, bTrustee?1:0);
		return sTmp;
	}
};

// 游戏开始
class CMD_S_GameStart {
	int wLandUser; // 地主玩家
	int bLandScore; // 地主分数
	int wCurrentUser; // 当前玩家
	int bBackCard[] = new int[3]; // 底牌扑克

	String getJsonData() {

		String sTmp = String.format(
				"  \"wLandUser\":%d  ,\"bLandScore\":%d , \"wCurrentUser\":%d  ,\"bBackCard\":[%d,%d,%d] ", wLandUser,
				bLandScore, wCurrentUser, bBackCard[0], bBackCard[1], bBackCard[2]);
		return sTmp;
	}
};

// 用户叫分
class CMD_S_LandScore {
	int wLandUser; // 叫分玩家
	int wCurrentUser; // 当前玩家
	int bLandScore; // 上次叫分
	int bCurrentScore; // 当前叫分

	String getJsonData() {
		String sTmp = String.format(
				"  \"wLandUser\":%d  ,\"wCurrentUser\":%d , \"bLandScore\":%d  ,\"bCurrentScore\":%d ", wLandUser,
				wCurrentUser, bLandScore, bCurrentScore);
		return sTmp;
	}
};

// 用户加入桌子
class CMD_S_UserEnterTable {
	int dwUserID;// 新加进的用户ID
	String szName; // 用户名字
	int wTableID;// 桌子索引号
	int wCharID;// 桌子索引号
	int lTableType;
	int lBaseScore;// CellScore

	String getJsonData() {

		String sTmp = String.format(
				"\"dwUserID\":%d ,\"szName\":\"%s\"  ,\"wTableID\":%d  ,\"wCharID\":%d  ,\"lTableType\":%d  ,\"lBaseScore\":%d   ",
				dwUserID, szName, wTableID, wCharID, lTableType, lBaseScore);
		return sTmp;
	}
};

class tagOutCardResult_Server {
	int cbCardCount; // 扑克数目
	int cbResultCard[] = new int[Constants.MAX_COUNT]; // 结果扑克
};

// 栈结构
class tagStackHandCardInfo {

	// 内联函数

	// 构造函数
	public tagStackHandCardInfo() {
		m_HandCardInfoFreeArray.clear();
		m_HandCardInfoArray.clear();
	}

	// 元素压栈
	void Push(tagHandCardInfo_Server pHandCardInfo) {
		tagHandCardInfo_Server pNewHandCardInfo = null;

		int nECount = m_HandCardInfoFreeArray.size();
		if (nECount > 0) {
			// 获取元素
			pNewHandCardInfo = m_HandCardInfoFreeArray.get(nECount - 1);
			// 移除元素
			m_HandCardInfoFreeArray.pop();
		} else {
			// 申请空间
			pNewHandCardInfo = new tagHandCardInfo_Server();
		}

		// 元素赋值
		Constants.CopyMemory(pNewHandCardInfo.cbHandCardData, pHandCardInfo.cbHandCardData);
		pNewHandCardInfo.cbHandCardCount = pHandCardInfo.cbHandCardCount;
		pNewHandCardInfo.CardTypeResult = pHandCardInfo.CardTypeResult.clone();
		// 压入栈顶
		m_HandCardInfoArray.push(pNewHandCardInfo);
	}

	// 弹出栈顶
	void Pop() {

		// 非空判断
		if (IsEmpty())
			return;

		// 获取元素
		int nECount = m_HandCardInfoArray.size();
		tagHandCardInfo_Server pTopHandCardInfo = m_HandCardInfoArray.get(nECount - 1);

		// 移除元素
		m_HandCardInfoArray.pop();

		// 保存空间
		m_HandCardInfoFreeArray.push(pTopHandCardInfo);
	}

	// 初始栈
	void InitStack() {
		// 保存空间
		while (0 < m_HandCardInfoArray.size()) {
			tagHandCardInfo_Server pHandCardInfo = (m_HandCardInfoArray.firstElement());
			m_HandCardInfoArray.remove(m_HandCardInfoArray.firstElement());
			m_HandCardInfoFreeArray.push(pHandCardInfo);
		}
	}

	// 清空栈
	void ClearAll() {
		m_HandCardInfoArray.clear();
		m_HandCardInfoFreeArray.clear();
	}

	// 获取栈顶
	tagHandCardInfo_Server GetTop(tagHandCardInfo_Server pHandCardInfo) {

		// 非空判断
		if (IsEmpty()) {
			return null;
		}

		// 获取元素
		int nECount = m_HandCardInfoArray.size();
		pHandCardInfo = m_HandCardInfoArray.get(nECount - 1);
		return pHandCardInfo;
	}

	// 空判断
	boolean IsEmpty() {
		return m_HandCardInfoArray.isEmpty();
	}

	// 成员变量
	Stack<tagHandCardInfo_Server> m_HandCardInfoFreeArray = new Stack<>(); // 扑克信息
	Stack<tagHandCardInfo_Server> m_HandCardInfoArray = new Stack<>(); // 扑克信息

};

class tagOutCardTypeResult_Server {
	int cbCardType; // 扑克类型
	int cbCardTypeCount; // 牌型数目
	int cbEachHandCardCount[] = new int[Constants.MAX_TYPE_COUNT];// 每手个数
	int cbCardData[][] = new int[Constants.MAX_TYPE_COUNT][Constants.MAX_COUNT];// 扑克数据

	public static void init(tagOutCardTypeResult_Server[] arrays) {
		for (int i = 0; i < arrays.length; i++) {
			arrays[i] = new tagOutCardTypeResult_Server();
		}
	}
};

// 扑克信息
class tagHandCardInfo_Server {
	int cbHandCardData[] = new int[Constants.MAX_COUNT]; // 扑克数据
	int cbHandCardCount; // 扑克数目
	tagOutCardTypeResult_Server CardTypeResult[] = new tagOutCardTypeResult_Server[12 + 1]; // 分析数据
	{
		for (int i = 0; i < CardTypeResult.length; i++) {
			CardTypeResult[i] = new tagOutCardTypeResult_Server();
		}
	}

	// 初始数据
	tagHandCardInfo_Server() {
		Constants.ZeroMemory(cbHandCardData);
		cbHandCardCount = 0;
	}
};

// 分析结构
class tagAnalyseResult_Server {
	int cbFourCount; // 四张数目
	int cbThreeCount; // 三张数目
	int cbDoubleCount; // 两张数目
	int cbSignedCount; // 单张数目
	int cbFourCardData[] = new int[Constants.MAX_COUNT]; // 四张扑克
	int cbThreeCardData[] = new int[Constants.MAX_COUNT]; // 三张扑克
	int cbDoubleCardData[] = new int[Constants.MAX_COUNT]; // 两张扑克
	int cbSignedCardData[] = new int[Constants.MAX_COUNT]; // 单张扑克
};

// 用户规则
class tagUserRule {
	boolean bPassword; // 设置密码
	boolean bLimitWin; // 限制胜率
	boolean bLimitFlee; // 限制逃跑
	boolean bLimitScore; // 限制分数
	boolean bCheckSameIP; // 效验地址
	int wWinRate; // 胜率限制
	int wFleeRate; // 限制逃跑
	int lMaxScore; // 最高分数
	int lLessScore; // 最低分数
	String szPassword; // 桌子密码
};

// 用户积分信息
class tagUserScore {
	int lScore; // 用户分数
	int lGameGold; // 游戏金币//
	int lStorageGold; // 存储金币
	int lWinCount; // 胜利盘数
	int lLostCount; // 失败盘数
	int lDrawCount; // 和局盘数
	int lFleeCount; // 断线数目
	int lExperience; // 用户经验
};



class IJsonExport {
	public String toString() {
		return getJsonData();
	}

	private String getJsonData() {
		return "";
	}

	public static String sprintf_BYTE(int by[][], int count) {

		int tmpCardData[] = new int[count]; // 用户扑克
		for (int i = 0; i < by.length; i++) {
			for (int k = 0; k < by[i].length; k++) {
				tmpCardData[i * by[i].length + k] = by[i][k];
			}
		}
		String strCardData = sprintf_BYTE(tmpCardData, count);
		return strCardData;
	}

	public static String sprintf_BYTE(Integer by[][], int count) {

		int tmpCardData[] = new int[count]; // 用户扑克
		for (int i = 0; i < by.length; i++) {
			for (int k = 0; k < by[i].length; k++) {
				tmpCardData[i * by[i].length + k] = by[i][k];
			}
		}
		String strCardData = sprintf_BYTE(tmpCardData, count);
		return strCardData;
	}

	public static String sprintf_BYTE(Integer by[], int count) {
		return sprintf_INT32(by, count);
	}

	public static String sprintf_BYTE(int by[], int count) {
		return sprintf_INT32(by, count);
	}

	public static String sprintf_DWORD(int dw[], int count) {
		return sprintf_INT32(dw, count);
	}

	public static String sprintf_INT32(Integer dw[], int count) {
		if (count < 1) {
			return "";
		}
		StringBuffer out_str = new StringBuffer();
		out_str.append(dw[0]);
		for (int i = 1; i < count; i++) {
			out_str.append(",");
			out_str.append(dw[i]);
		}
		return out_str.toString();
	}

	public static String sprintf_INT32(int dw[], int count) {
		if (count < 1) {
			return "";
		}
		StringBuffer out_str = new StringBuffer();
		out_str.append(dw[0]);
		for (int i = 1; i < count; i++) {
			out_str.append(",");
			out_str.append(dw[i]);
		}
		return out_str.toString();
	}

	public static String sprintf_DOUBLE(double dw[], int count) {
		if (count < 1) {
			return "";
		}
		StringBuffer out_str = new StringBuffer();
		out_str.append(big2(dw[0]));
		for (int i = 1; i < count; i++) {
			out_str.append(",");
			out_str.append(big2(dw[i]));
		}
		return out_str.toString();
	}
	static protected String big2(double d) {
		BigDecimal d1 = new BigDecimal(Double.toString(d)); 
		BigDecimal d2 = new BigDecimal(Integer.toString(1));
		return d1.divide(d2,2,BigDecimal.ROUND_HALF_UP).toString();
	}
}

class SUBCMD_S_Param extends IJsonExport {

	int m_dwTableID;// 房间ID
	String szParam;
	String szRoomDesc;
	
	String getJsonData() {

		String mjmsg = String.format("param|%d|%s|%s", m_dwTableID, szParam,szRoomDesc);

		JSONObject json = new JSONObject();
		json.put("command", "pdkmsg");
		json.put("pdkmsg", mjmsg);

		return json.toString();
	}
};

class SSeatInfo {
	int m_lUid;// UID
	int m_iTotalScore;// COIN
	String m_NickName;// NICKNAME
	int m_iBetCoin;//
	int m_cbGender;//
	int m_iAvatar;//
	int m_iSeatId;
	int m_cbUserStatus;// 用户状态
	int m_iVipLevel;// VIP LEVEL
	int m_iTitle;// 称号
	int m_isLookon;// 是否观众
	String szIP;
	double m_iTotalCoin;

	public String toString() {

		String pdkmsg = String.format("%d#%d#%s#%d#%d#%d#%d#%d#%d#%d#%s#%s", m_lUid, m_iTotalScore, m_NickName, m_iBetCoin,
				m_cbGender, m_iAvatar, m_cbUserStatus, m_iVipLevel, m_iTitle, m_isLookon, szIP,big2(m_iTotalCoin));
		return pdkmsg;
	}
	protected String big2(double d) {
		BigDecimal d1 = new BigDecimal(Double.toString(d)); 
		BigDecimal d2 = new BigDecimal(Integer.toString(1));
		return d1.divide(d2,2,BigDecimal.ROUND_HALF_UP).toString();
	}
};


class SUBCMD_S_Sit extends IJsonExport{		
	int	 m_lUid;      	
	int	 m_wUserChairID;//座位ID 
	int	 m_dwTableID;//房间ID
	int	 m_lUserScore;
	String	szNickName;
	int	m_cbGender;
	int		m_iAvatar;
	String	szIP;
	String m_param;
	double m_lUserCoin;
	double dwcKouYingRate;
	int m_kouYingJuShu;
	
	String getJsonData() {

		String pdkmsg = String.format("sit|%d|%d|%d|%d|%s|%d|%d|%s|%s|%s|%g|%d", m_lUid, m_wUserChairID, m_dwTableID,
				m_lUserScore, szNickName, m_cbGender, m_iAvatar, szIP,m_param,big2(m_lUserCoin),dwcKouYingRate,m_kouYingJuShu);
		JSONObject json = new JSONObject();
		json.put("command", "pdkmsg");
		json.put("pdkmsg", pdkmsg);

		return json.toString();
	}
};

//头像
class SUBCMD_S_Avatar extends IJsonExport {
	int m_lUid;// 哪个玩家ID获得
	String szAvatarURL;

	String getJsonData() {

		String pdkmsg = String.format("avatar|%d|%s", m_lUid, szAvatarURL);
		JSONObject json = new JSONObject();
		json.put("command", "pdkmsg");
		json.put("pdkmsg", pdkmsg);

		return json.toString();
	}
};
//聊天表情
class SUBCMD_S_BiaoQing extends IJsonExport {
	int m_lUid;// 哪个玩家ID获得
	int m_wUserChairID;// 玩家座位
	int m_iBiaoQingIndex;

	String getJsonData() {

		String pdkmsg = String.format("biaoqing|%d|%d|%d", m_lUid, m_wUserChairID, m_iBiaoQingIndex);
		JSONObject json = new JSONObject();
		json.put("command", "pdkmsg");
		json.put("pdkmsg", pdkmsg);

		return json.toString();
	}
};

//语音
class SUBCMD_S_YuYin extends IJsonExport {
	int m_lUid;// 哪个玩家ID获得
	int m_wUserChairID;// 玩家座位号
	int m_iYuYinIndex;

	String getJsonData() {

		String pdkmsg = String.format("yuyin|%d|%d|%d", m_lUid, m_wUserChairID, m_iYuYinIndex);
		JSONObject json = new JSONObject();
		json.put("command", "pdkmsg");
		json.put("pdkmsg", pdkmsg);

		return json.toString();
	}
};

//文字聊天
class SUBCMD_S_Chat extends IJsonExport {
	int m_lUid;// 哪个玩家ID获得
	int m_wUserChairID;// 玩家座位号
	String szContent;

	String getJsonData() {

		String pdkmsg = String.format("chat|%d|%d|%s", m_lUid, m_wUserChairID, szContent);
		JSONObject json = new JSONObject();
		json.put("command", "pdkmsg");
		json.put("pdkmsg", pdkmsg);

		return json.toString();
	}
};

//语音
class SUBCMD_S_Voice extends IJsonExport {
	int m_lUid;// 哪个玩家ID获得
	int m_wUserChairID;// 玩家座位号
	int seconds;
	String szVoiceURL;

	String getJsonData() {

		String pdkmsg = String.format("voice|%d|%d|%d|%s", m_lUid, m_wUserChairID, seconds, szVoiceURL);
		JSONObject json = new JSONObject();
		json.put("command", "pdkmsg");
		json.put("pdkmsg", pdkmsg);

		return json.toString();
	}
};
class SUBCMD_S_VoiceMsg extends IJsonExport{
	int m_lUid;
	int m_wUserChairID;
	int m_maxClip;
	int m_currClip;
	float seconds;
	String data;
	
	String getJsonData() {

		String mjmsg = String.format("voicemsg|%d|%d|%f|%s|%d|%d", m_lUid, m_wUserChairID, seconds, data,m_maxClip,m_currClip);
		JSONObject json = new JSONObject();
		json.put("command", "pdkmsg");
		json.put("pdkmsg", mjmsg);

		return json.toString();
	}
};

class SUBCMD_S_GameIap extends IJsonExport{
	int uid;
	int seat;
	double coin;
	String getJsonData(){
		String mjmsg = String.format("gameiap|%d|%d|%g", uid,seat,coin);
		JSONObject json = new JSONObject();
		json.put("command", "pdkmsg");
		json.put("pdkmsg", mjmsg);
		return json.toString();
	}
}
class SUBCMD_S_ExprMsg extends IJsonExport{
	int m_uid1;
	int m_uid2;
	int m_index;
	String getJsonData() {

		String mjmsg = String.format("expr|%d|%d|%d", m_uid1, m_uid2,m_index);
		JSONObject json = new JSONObject();
		json.put("command", "pdkmsg");
		json.put("pdkmsg", mjmsg);

		return json.toString();
	}
};
class SUBCMD_S_TryDismissRoom extends IJsonExport {
	int lUid;
	String szNickName;//
	int dwTableID;// 房间ID

	String getJsonData() {
		String pdkmsg = String.format("try_dismissroom|%d|%s|%d", lUid, szNickName, dwTableID);

		JSONObject json = new JSONObject();
		json.put("command", "pdkmsg");
		json.put("pdkmsg", pdkmsg);

		return json.toString();
	}
};

class SUBCMD_S_DismissRoom extends IJsonExport {
	int cbResult;
	int lUid;
	int m_wUserChairID;// 座位ID
	int m_dwTableID;// 房间ID

	String getJsonData() {

		String pdkmsg = String.format("dismissroom|%d|%d|%d|%d", cbResult, lUid, m_wUserChairID, m_dwTableID);
		JSONObject json = new JSONObject();
		json.put("command", "pdkmsg");
		json.put("pdkmsg", pdkmsg);

		return json.toString();
	}
};

class SUBCMD_S_Table extends IJsonExport{ //同步房间玩家信息
	int	 m_dwTableID;//房间ID			
	int	m_bTableStarted;//只要开始玩
	int	m_byRound;//
	int	m_byMaxRound;//		
	int	m_bGameStarted;//游戏开始	
	int	m_cntUser;//玩家数量
	int	m_cntLookon;//观众数量
	String m_param;
	public SUBCMD_S_Table(){
		for (int i = 0; i < 3; i++) {
			 m_seatInfo[i] = new SSeatInfo();
		}
	}
	SSeatInfo	m_seatInfo[] = new SSeatInfo[3];
	public String getJsonData(){
		String pdkmsg = String.format("table|%d|%d|%d|%d|%d|%d|%d|%s|%s|%s|%s", m_dwTableID, m_bTableStarted, m_byRound, m_byMaxRound,m_bGameStarted, m_cntUser, m_cntLookon,
			m_seatInfo[0].toString(), m_seatInfo[1].toString(), m_seatInfo[2].toString(),m_param);
		JSONObject json = new JSONObject();
		json.put("command", "pdkmsg");
		json.put("pdkmsg", pdkmsg);	
		
		return json.toString();		
	}
};


class SUBCMD_S_TableBegin extends IJsonExport {
	String strParam;
	int byZhuang;
	long byRound;//
	long byMaxRound;
	int byYuPai[] = new int[3];//
	int byCurrentUser;
	int lScore[] = new int[3];
	int lRoundScore[] = new int[3];
	int byLastOutCard[] = new int[2];

	String getJsonData() {
		String stryuPai = sprintf_INT32(byYuPai, 3);
		String strScore = sprintf_INT32(lScore, 3);
		String strRoundScore = sprintf_INT32(lRoundScore, 3);
		String strlastOutCard = sprintf_INT32(byLastOutCard, 2);
		
		String pdkmsg = String.format("table_begin|%s|%d|%d|%d|%s|%d|%s|%s|%s", strParam, byZhuang, byRound,
				byMaxRound, stryuPai, byCurrentUser, strScore, strRoundScore, strlastOutCard);
		JSONObject json = new JSONObject();
		json.put("command", "pdkmsg");
		json.put("pdkmsg", pdkmsg);
		return json.toString();
	}
};


class SUBCMD_S_TableSide extends IJsonExport {
	int bySeatID;
	int card[] = new int[20];

	String getJsonData() {

		String strCard = sprintf_BYTE(card, 20);
	
		String pdkmsg = String.format("table_side|%d|%s", bySeatID, strCard);
		JSONObject json = new JSONObject();
		json.put("command", "pdkmsg");
		json.put("pdkmsg", pdkmsg);
		
		return json.toString();
	}
};

class SUBCMD_S_TableEnd extends IJsonExport {
	int cbSceneStatus;

	String getJsonData() {

		String pdkmsg = String.format("table_end|%d", cbSceneStatus);
		JSONObject json = new JSONObject();
		json.put("command", "pdkmsg");
		json.put("pdkmsg", pdkmsg);

		return json.toString();
	}
};



class SUBCMD_S_REPORT extends IJsonExport {
	int cbReason;
	int whoDismiss;
	int vecMaxWinScore[] = new int[3];
	int vecWinScore[] = new int[3];
	int vecLoseScore[] = new int[3];
	double vecResultScore[] = new double[3];
	int vecWinCount[] = new int[3];
	int vecBombCount[] = new int[3];
	int vecGuanMenCount[] = new int[3];
	String getJsonData() {


		String strMaxWinScore = sprintf_INT32(vecMaxWinScore, 3);
		String strWinScore = sprintf_INT32(vecWinScore, 3);
		String strLoseScore = sprintf_INT32(vecLoseScore, 3);
		String strResultScore = sprintf_DOUBLE(vecResultScore, 3);
		String strWinCount = sprintf_INT32(vecWinCount,3);
		String strBombCount = sprintf_INT32(vecBombCount,3);
		String strGuanMenCount = sprintf_INT32(vecGuanMenCount,3);

		String pdkmsg = String.format("report|%d|%d|%s|%s|%s|%s|%s|%s|%s", cbReason, whoDismiss, strMaxWinScore, strWinScore,
				strLoseScore, strResultScore,strWinCount,strBombCount,strGuanMenCount);
		JSONObject json = new JSONObject();
		json.put("command", "pdkmsg");
		json.put("pdkmsg", pdkmsg);

		return json.toString();
	}

	String getData() {

		String strWinScore = sprintf_INT32(vecWinScore, 3);
		String strLoseScore = sprintf_INT32(vecLoseScore, 3);
		String strResultScore = sprintf_DOUBLE(vecResultScore, 3);

		return String.format("report|%d|%d|%s|%s|%s", cbReason, whoDismiss, strWinScore, strLoseScore, strResultScore);
	}
};

class SUBCMD_S_AgreeDismissRoom extends IJsonExport {
	int lUid;
	String szNickName;//
	int dwTableID;// 房间ID

	String getJsonData() {
		String pdkmsg = String.format("agree_dismissroom|%d|%s|%d", lUid, szNickName, dwTableID);

		JSONObject json = new JSONObject();
		json.put("command", "pdkmsg");
		json.put("pdkmsg", pdkmsg);

		return json.toString();
	}
};

class SUBCMD_S_RefuseDismissRoom extends IJsonExport {
	int lUid;
	String szNickName;//
	int dwTableID;// 房间ID

	String getJsonData() {
		String pdkmsg = String.format("refuse_dismissroom|%d|%s|%d", lUid, szNickName, dwTableID);
		JSONObject json = new JSONObject();
		json.put("command", "pdkmsg");
		json.put("pdkmsg", pdkmsg);

		return json.toString();
	}
};

class SUBCMD_S_JieSuan extends IJsonExport {
	int nUserScore[] = new int[3];
	int lWinSeat = 0;
	double lShuiShou[] = new double[3];
	double lUserCoin[] = new double[3];
	double lWonLose[] = new double[3];
	public String getJsonData(){

		String strResultScore = sprintf_INT32(nUserScore, 3);
		String userCoin = sprintf_DOUBLE(lUserCoin,3);
		String userShui = sprintf_DOUBLE(lShuiShou,3);
		String wonLose = sprintf_DOUBLE(lWonLose,3);
		
		String pdkmsg = String.format("jiesuan|%s|%d|%s|%s|%s", strResultScore,lWinSeat,userShui,userCoin,wonLose);
		JSONObject json = new JSONObject();
		json.put("command", "pdkmsg");
		json.put("pdkmsg", pdkmsg);

		return json.toString();
	}
};

class SUBCMD_S_round extends IJsonExport {
	int round = 1;
	public String getJsonData(){

		
		String pdkmsg = String.format("round|%d", round);
		JSONObject json = new JSONObject();
		json.put("command", "pdkmsg");
		json.put("pdkmsg", pdkmsg);

		return json.toString();
	}
};


//文字聊天
class SUBCMD_S_Text extends IJsonExport {
	int m_lUid;// 哪个玩家ID获得
	int m_wUserChairID;// 玩家座位号
	String szContent;

	String getJsonData() {
		String pdkmsg = String.format("text|%d|%d|%s", m_lUid, m_wUserChairID, szContent);

		JSONObject json = new JSONObject();
		json.put("command", "pdkmsg");
		json.put("pdkmsg", pdkmsg);
		return json.toString();
	}
};



class SUBCMD_S_StandUp extends IJsonExport {

	int m_lUid;// 玩家ID
	int m_wUserChairID;// 座位ID
	int m_dwTableID;// 房间ID
	int leaveRoom;
	String getJsonData() {

		String pdkmsg = String.format("standup|%d|%d|%d|%d", m_lUid, m_wUserChairID, m_dwTableID,leaveRoom);
		JSONObject json = new JSONObject();
		json.put("command", "pdkmsg");
		json.put("pdkmsg", pdkmsg);

		return json.toString();
	}
};



class SUBCMD_S_InBack extends IJsonExport{
	int byActionUser;
	String getJsonData(){
		String mjmsg = String.format("inBack|%d", byActionUser);
		JSONObject json = new JSONObject();
		json.put("command", "pdkmsg");
		json.put("pdkmsg", mjmsg);
		return json.toString();
	}
}
class SUBCMD_S_InFore extends IJsonExport{
	int byActionUser;
	String getJsonData(){
		String mjmsg = String.format("inFore|%d", byActionUser);
		JSONObject json = new JSONObject();
		json.put("command", "pdkmsg");
		json.put("pdkmsg", mjmsg);
		return json.toString();
	}
}